﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Northwind.Interfaces.Data.Model;
using Northwind.Application;
using Northwind.Application.Model;
using GalaSoft.MvvmLight;
using Northwind.Data;

namespace Northwind.ViewModel
{
    public class OrderItemViewModel : ViewModelBase, IOrderDetailModel
    {
        #region Fields

        IOrderDetailModel _model;

        #endregion

        #region Constructors

        public OrderItemViewModel(IOrderModel order)
        {
            _model = new OrderDetailModel(new Order_Detail());
            this.Order = order;
        }

        #endregion

        #region IOrderDetailModel implementation
        public IProductModel Product
        {
            get
            {
                return _model.Product;
            }
            set
            {
                _model.Product = value;
                RaisePropertyChanged("Product");
            }
        }

        public IOrderModel Order
        {
            get
            {
                return _model.Order;
            }
            set
            {
                _model.Order = value;
                RaisePropertyChanged("Order");
            }
        }

        public int OrderID
        {
            get
            {
                return _model.OrderID;
            }
            set
            {
                RaisePropertyChanged("OrderID");
            }
        }

        public int ProductID
        {
            get
            {
                return _model.ProductID;
            }
            set
            {
                RaisePropertyChanged("ProductID");
            }
        }

        public decimal UnitPrice
        {
            get
            {
                return _model.UnitPrice;
            }
            set
            {
                _model.UnitPrice = value;
                RaisePropertyChanged("UnitPrice");
            }
        }

        public short Quantity
        {
            get
            {
                return _model.Quantity;
            }
            set
            {
                _model.Quantity = value;
                RaisePropertyChanged("Quantity");
            }
        }

        public float Discount
        {
            get
            {
                return _model.Discount;
            }
            set
            {
                _model.Discount = value;
                RaisePropertyChanged("Discount");
            }
        }

        #endregion

        #region Collections

        IEnumerable<IProductModel> _productsList;
        public IEnumerable<IProductModel> ProductsList
        {
            get
            {
                if (_productsList == null)
                {
                    _productsList = Core.Instance.NorthwindManager.GetProducts();
                }

                return _productsList;
            }
        }

        IProductModel _selectedProduct;
        public IProductModel SelectedProduct
        {
            get
            {
                return _selectedProduct;                
            }
            set
            {
                _selectedProduct = value;
                RaisePropertyChanged("SelectedProduct");
            }
        }

        #endregion

    }
}
